﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations;

namespace TraceThisItem.Domain.Initializers
{
	public class ItemConfiguration : EntityTypeConfiguration<Item>
	{
		public ItemConfiguration()
		{
			HasKey(i => i.Id)
			   .Property(i => i.Id)
			   .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

			Property(i => i.Description)
				.IsRequired()
				.IsUnicode(false)
                .IsMaxLength();

            Property(i => i.Subject)
                .HasMaxLength(50)
                .IsRequired()
                .IsUnicode(false);

            Property(i => i.Comments)
                .IsUnicode(false)
                .IsMaxLength();

			HasRequired(i => i.Team)
				.WithMany()
				.HasForeignKey(i => i.TeamId);

			HasRequired(i => i.Project)
				.WithMany(project => project.Items);

			/*HasRequired(i => i.CurrentStatus)
				.WithMany()
				.WillCascadeOnDelete(false);
			*/
			HasMany(i => i.Traceability)
				.WithRequired()
				.WillCascadeOnDelete(false);
		}
	}
}
